//
//  LogoTipView.m
//  LeaveLight
//
//  Created by pro1 on 2019/3/14.
//  Copyright © 2019 xsl. All rights reserved.
//

#import "LogoTipView.h"

@interface LogoTipView ()

@property (strong,nonatomic) UILabel *shareForm;
@property (strong,nonatomic) UILabel *tip;
@property (strong,nonatomic) UIImageView *qrCode;
@property (strong,nonatomic) UIImageView *bgImage;


@end

@implementation LogoTipView

- (instancetype)init{
    self = [super init];
    if (self) {
        [self addSubview:self.shareForm];
        [self addSubview:self.tip];
        [self addSubview:self.qrCode];
        [self addSubview:self.bgImage];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.font = _font;
    [self updateUIMas];
}

- (void)updateUIMas{
    switch (_style) {
        case LogoTipViewStyleText:
        {
            _shareForm.textAlignment = NSTextAlignmentCenter;
            _shareForm.hidden = NO;
            _tip.hidden = YES;
            _qrCode.hidden = YES;
            _bgImage.hidden = YES;
            [_shareForm mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.left.right.equalTo(self).offset(0);
            }];
        }
            break;
        case LogoTipViewStyleQrCode:
        {
            _shareForm.textAlignment = NSTextAlignmentLeft;
            _shareForm.hidden = NO;
            _tip.hidden = NO;
            _qrCode.hidden = NO;
            _bgImage.hidden = YES;
            
            CGFloat valueWidth = (30 + [_shareForm.text sizeWithAttributes:@{NSFontAttributeName:self.shareForm.font}].width + 10);
            
            [_qrCode mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.equalTo(self).offset(0);
                make.left.equalTo(self).offset((self.frame.size.width - valueWidth)/2);
                make.width.offset(30);
            }];
            
            [_shareForm mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self).offset(0);
                make.left.equalTo(self.qrCode.mas_right).offset(10);
            }];
            
            [_tip mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.shareForm.mas_bottom).offset(0);
                make.left.equalTo(self.qrCode.mas_right).offset(10);
                make.bottom.equalTo(self).offset(0);
                make.height.equalTo(self.shareForm);
            }];
            
        }
            break;
        case LogoTipViewStyleImage:
        {
            _shareForm.textAlignment = NSTextAlignmentCenter;
            _shareForm.hidden = YES;
            _tip.hidden = YES;
            _qrCode.hidden = YES;
            _bgImage.hidden = NO;
            [_bgImage mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.left.right.equalTo(self).offset(0);
            }];
        }
            break;
            
        default:
            break;
    }
}

- (UIImageView *)qrCode{
    if (!_qrCode) {
        _qrCode = [[UIImageView alloc] init];
        _qrCode.contentMode = UIViewContentModeScaleAspectFit;
//        _qrCode.backgroundColor = UIColorMake(239, 239, 239);
        _qrCode.image = [UIImage imageNamed:@"二维码_down"];
    }
    return _qrCode;
}


- (UIImageView *)bgImage{
    if (!_bgImage) {
        _bgImage = [[UIImageView alloc] init];
        _bgImage.contentMode = UIViewContentModeScaleAspectFit;
        _bgImage.backgroundColor = UIColorMake(239, 239, 239);
    }
    return _bgImage;
}

- (UILabel *)shareForm{
    if (!_shareForm) {
        _shareForm = [[UILabel alloc] init];
        _shareForm.textColor = UIColorMakeWithHex(@"#D0D4D8");
        _shareForm.font = [UIFont systemFontOfSize:12];
        _shareForm.text = @"分享自留光APP";
        _shareForm.numberOfLines = 0;
    }
    return _shareForm;
}

- (UILabel *)tip{
    if (!_tip) {
        _tip = [[UILabel alloc] init];
        _tip.textColor = UIColorMakeWithHex(@"#D0D4D8");
        _tip.font = [UIFont systemFontOfSize:10];
        _tip.text = @"一抹时光 一抹情";
    }
    return _tip;
}

- (void)setFont:(UIFont *)font{
    _font = font;
    if (_font) {
        if (_style == LogoTipViewStyleText) {
            _shareForm.font = [_font fontWithSize:12];
        }
        else{
            _tip.font = _shareForm.font = [_font fontWithSize:10];
        }
    }
    else{
        if (_style == LogoTipViewStyleText) {
            _shareForm.font = [UIFont systemFontOfSize:12];
        }
        else{
            _tip.font = _shareForm.font = [UIFont systemFontOfSize:10];
        }
    }
}



@end
